package com.coolpad.job.device.util;


import com.alibaba.fastjson.JSONObject;
import com.coolpad.Utils.Md5Utils;
import com.coolpad.job.device.model.DeviceLocationDTO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述:<br/>
 *
 * @Author:shengtao_yang
 * @Date: 2020/12/21 13:27
 * @since: 1.0.0
 */
public class KafkaMessageUtils {


    /**
     * dto转换为kafka定位消息
     * @param deviceLocation
     * @return
     */
    public static List<JSONObject> convert2Message(DeviceLocationDTO deviceLocation) {

        return deviceLocation.getLoc().stream()
                .map(locationInfo ->
                        new JSONObject(){
                            {
                                put(Constants.DEVICE_INFO.IMEI1_MD5, Md5Utils.md5(deviceLocation.getImei1()));
                                put(Constants.DEVICE_INFO.MODEL,deviceLocation.getModel());
                                put(Constants.LOCATION.timestamp,locationInfo.getTimestamp());
                                put(Constants.LOCATION.ip,locationInfo.getIp());
                                put(Constants.LOCATION.gps,locationInfo.getGps());
                                put(Constants.LOCATION.connect_wifi,locationInfo.getConnectWifi());
                                put(Constants.LOCATION.near_wifi,locationInfo.getNearWifi());
                                put(Constants.LOCATION.cell,locationInfo.getCell());
                                put(Constants.LOCATION.dt, DateUtils.toYHD(locationInfo.getTimestamp()));
                            }
                        }
                ).collect(Collectors.toList());
    }
}
